# -*- coding: utf-8 -*-
class PurchaseReturned < ActiveRecord::Base
  has_many :purchase_returned_details ,:dependent => :destroy  #级联删除子表

  belongs_to :vendor
  belongs_to :employee      #制单人员
  belongs_to :department
  belongs_to :company

  belongs_to :purchase_order

  belongs_to :associate_auditor, :class_name => 'Employee', :foreign_key => 'associate_auditor_id'

  belongs_to :warehouse_employee, :class_name => 'Employee', :foreign_key => 'warehouse_employee_id'

  scope :findAllPurchaseReturneds, ->(conditionsStr,conditionsHash,paramsHash) { includes( [:employee,:department,:vendor,:associate_auditor,:warehouse_employee]).where([conditionsStr,conditionsHash]).offset(paramsHash[:offset]).limit(paramsHash[:limit]).order('updated_at DESC')}

  scope :countAllPurchaseReturneds, ->(conditionsStr,conditionsHash) { where([conditionsStr,conditionsHash]).count()}

end
